package com.wxf.web;


import com.wxf.bean.Student;
import com.wxf.service.GradeService;
import com.wxf.service.StudentService;
import com.wxf.service.impl.GradeServiceImpl;
import com.wxf.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/Educational/student/modifyStudentInfo")
public class DisplayBeforeModifyStudentInfoServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 当用户点击list.jsp中的修改时，跳转到add.jsp，在add.jsp中，首先要展示所选学生的信息
        // 1-获取请求参数
        String stuNo = req.getParameter("stuNumber");
        System.out.println(stuNo);
        // 2-后台处理
        StudentService studentService = new StudentServiceImpl();
        Student student = studentService.displayBeforeModifyStudentInfo(stuNo);
        System.out.println(student);
        if(student!=null){
            req.setAttribute("stuList",student);
            GradeService gradeService = new GradeServiceImpl();
            List gradeList = gradeService.getGradeInfo();
            req.setAttribute("gradeList",gradeList);
            req.setCharacterEncoding("utf-8");
            req.getRequestDispatcher("edit.jsp").forward(req,resp);
        }else{
            resp.sendRedirect("/list.jsp");
        }
    }
}
